package com.t.bricks.bussiness.service.userandrole.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.t.bricks.bussiness.db.dao.userandrole.UserAndRoleDao;
import com.t.bricks.bussiness.service.userandrole.UserAndRoleService;
import com.t.bricks.model.MsgEmity;
import com.t.bricks.utils.spring.ModuleUtil;

/**
 * 用户与角色关系表'UserAndRole表'基本业务操作类接口实现
 */
@Service
public class UserAndRoleServiceImpl implements UserAndRoleService {

	@Autowired
	private UserAndRoleDao userAndRoleDao;
	
	//----------------------------- 自动生成代码结束 -----------------------------//
	
	/**
	 * 添加用户与角色关联信息
	 * @param sUserId 用户编号
	 * @param sRoleList 角色集合
	 * @return
	 */
	@Override
	public MsgEmity add(String sUserId, String sRoleList) {
		if (null == sUserId || "".equals(sUserId.trim())) {
			return new MsgEmity(false, "用户编号不能为空！", 8001);
		}
		
		String currentLoginUserId = ModuleUtil.currentLoginUserId();//取当前登录用户编号
		return userAndRoleDao.add(sUserId.trim(), sRoleList, currentLoginUserId);
	}
	
	/**
	 * 查询用户所拥有的角色
	 * @param sUserId
	 * @return
	 */
	@Override
	public MsgEmity findRoleListByUserId(String sUserId) {
		if (null == sUserId || "".equals(sUserId.trim())) {
			return new MsgEmity(false, "编号不能为空！", 8001);
		}
		
		return userAndRoleDao.findRoleListByUserId(sUserId);
	}
	
}
